using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for ProcessUser
/// </summary>
public class ProcessUser
{
	public static SqlConnection connection;
    public static DataSet dataset;
        
    public ProcessUser()
    {
        //
        // TODO: Add constructor logic here//

        if (connection == null)
        {
            try
            {
                String conn = System.Configuration.ConfigurationManager.AppSettings["conn"];
                connection = new SqlConnection(conn);
                if (dataset == null) dataset = new DataSet();
            }
            catch (Exception se)
            {
                HttpContext.Current.Response.Redirect("UserThongbao.aspx?id=khongconnectduoc");
                
            }
        }
    }

    #region Category
        
    public void selectCategory()
    {
        try
        {
            if (dataset.Tables["Category"] != null) dataset.Tables.Remove("Category"); ;
           
            SqlDataAdapter adapter = new SqlDataAdapter("select * from Category", connection);
            adapter.Fill(dataset, "Category");
        }
        catch (Exception e)
        {

            HttpContext.Current.Response.Redirect("UserThongbao.aspx?id=selectCategory");
        }
    }

    public void selectRootCategory()
    {
        try
        {
            if (dataset.Tables["RootCategory"] != null) dataset.Tables.Remove("RootCategory"); ;

            SqlDataAdapter adapter = new SqlDataAdapter("select * from Category where ParentID = 0", connection);
            adapter.Fill(dataset, "RootCategory");
        }
        catch (Exception e)
        {

            HttpContext.Current.Response.Redirect("UserThongbao.aspx?id=selectCategory");
        }
    }

    public void selectChildCategory(string parentID)
    {
        try
        {
            if (dataset.Tables["ChildCategory"] != null) dataset.Tables.Remove("ChildCategory"); ;

            SqlDataAdapter adapter = new SqlDataAdapter("select * from Category where parentID =" + int.Parse(parentID), connection);
            adapter.Fill(dataset, "ChildCategory");
        }
        catch (Exception e)
        {

            HttpContext.Current.Response.Redirect("UserThongbao.aspx?id=selectCategory");
        }
    }

    #endregion
}



